<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="styleB/css.css"/>
    <script type="text/javascript" src="../../script/jquery-1.7.2.js"></script>
    <script type="text/javascript">
        $(function () {
            //删除用户的方法
            function deleteEmp() {
                var name = $(this).parents("tr").find("td:eq(0)").text();
                var flag = confirm("确认删除" + name + "吗？");
                if (flag) {
                    $(this).parents("tr").remove();
                }
                //取消默认行为
                return false;
            }

            //删除用户
            /*$("#employeeTable a").click(function () {
                deleteEmp();
            });*/ // 此种写法有误
            // $("#employeeTable a").click(deleteEmp); // OK
            $("#employeeTable a").live("click", deleteEmp); // OK

            //添加员工
            $("#addEmpButton").click(function () {
                var name = $("#empName").val();
                var email = $("#email").val();
                var salary = $("#salary").val();
                $("#employeeTable").append("<tr>\n" +
                    "        <td>" + name + "</td>\n" +
                    "        <td>" + email + "</td>\n" +
                    "        <td>" + salary + "</td>\n" +
                    "        <td><a href=\"#\">Delete</a></td>\n" +
                    "    </tr>");
            });
        });
    </script>
</head>
<body>

<table id="employeeTable">
    <tr>
        <th>Name</th>
        <th>Email</th>
        <th>Salary</th>
        <th>&nbsp;</th>
    </tr>
    <tr>
        <td>Tom</td>
        <td>tom@tom.com</td>
        <td>5000</td>
        <td><a href="#">Delete</a></td>
    </tr>
    <tr>
        <td>Jerry</td>
        <td>jerry@sohu.com</td>
        <td>8000</td>
        <td><a href="#">Delete</a></td>
    </tr>
    <tr>
        <td>Bob</td>
        <td>bob@tom.com</td>
        <td>10000</td>
        <td><a href="#">Delete</a></td>
    </tr>
</table>

<div id="formDiv">

    <h4>添加新员工</h4>

    <table>
        <tr>
            <td class="word">name:</td>
            <td class="inp">
                <input type="text" name="empName" id="empName"/>
            </td>
        </tr>
        <tr>
            <td class="word">email:</td>
            <td class="inp">
                <input type="text" name="email" id="email"/>
            </td>
        </tr>
        <tr>
            <td class="word">salary:</td>
            <td class="inp">
                <input type="text" name="salary" id="salary"/>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <button id="addEmpButton" value="abc">
                    Submit
                </button>
            </td>
        </tr>
    </table>

</div>

</body>
</html>
